package com.yb.forum.config;

import com.yb.forum.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
// 表示一个配置类,让Spring管理起来
@Configuration
public class AppInterceptorConfigurer implements WebMvcConfigurer {

    // 注入自定义的登录拦截器
    @Resource
    private LoginInterceptor loginInterceptor;
    /**
     * 添加拦截规则
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns()
                .addPathPatterns("/**")
                .excludePathPatterns("/sign-in.html")   // 登录
                .excludePathPatterns("/sign-up.html")   // 注册
                .excludePathPatterns("/user/login")     // 登录
                .excludePathPatterns("/user/register")  // 注册
                .excludePathPatterns("/user/logout")    // 退出登录
                .excludePathPatterns("/v3*/**")         // swagger相关
                .excludePathPatterns("/swagger*/**")
                .excludePathPatterns("/dist/**")        // 所有静态文件
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/image/**")
                .excludePathPatterns("/**.ico");
    }
}
